package com.alibaba.algo.config;

import com.alibaba.algo.components.redis.config.RedisBaseConfig;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;

/**
 * Created by IntelliJ IDEA.
 * User: glorysongglory
 * Date: 2020/11/6
 * Time: 9:45
 */

@Configuration
public class RedisConfig extends RedisBaseConfig {

    @Bean
    public RedisTemplate<String, Object> permissionRedisTemplate(@Value("${permission.redis.host}") String hostName,
                                                                 @Value("${permission.redis.port}") int port, @Value("${permission.redis.database}") int database,
                                                                 @Value("${permission.redis.password}") String password,
                                                                 @Value("${permission.redis.pool.max-idle}") int maxIdle,
                                                                 @Value("${permission.redis.pool.min-idle}") int minIdle,
                                                                 @Value("${permission.redis.pool.max-active}") int maxActive,
                                                                 @Value("${permission.redis.pool.max-wait}") int maxWait) {
        RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
        redisTemplate.setConnectionFactory(
                getRedisConnctionFactory(hostName, port, database, password, maxIdle, minIdle, maxActive, maxWait));
        redisTemplate.setDefaultSerializer(new StringRedisSerializer());
        return redisTemplate;
    }

}
